home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Devices and Hardware / Drivers / Load PCI Driver / MoreFiles / DirectoryCopy.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  20.6 KB  |  497 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        DirectoryCopy.h
  3.     
  4.     Description:A robust, general purpose directory copy routine.
  5.  
  6.     Author:        JL
  7.  
  8.     Copyright:     Copyright: © 1992-1999 by Apple Computer, Inc.
  9.                 all rights reserved.
  10.     
  11.     Disclaimer:    You may incorporate this sample code into your applications without
  12.                 restriction, though the sample code has been provided "AS IS" and the
  13.                 responsibility for its operation is 100% yours.  However, what you are
  14.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  15.                 after having made changes. If you're going to re-distribute the source,
  16.                 we require that you make it clear in the source that the code was
  17.                 descended from Apple Sample Code, but that you've made changes.
  18.     
  19.     Change History (most recent first):
  20.                 6/25/99    Updated for Metrowerks Codewarror Pro 2.1(KG)
  21.  
  22. */
  23.  
  24.  
  25. #ifndef __DIRECTORYCOPY__
  26. #define __DIRECTORYCOPY__
  27.  
  28. #include <Types.h>
  29. #include <Files.h>
  30.  
  31. #include "Optimization.h"
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36.  
  37. /*****************************************************************************/
  38.  
  39. enum
  40. {
  41.     getNextItemOp            = 1,    /* couldn't access items in this directory - no access privileges */
  42.     copyDirCommentOp        = 2,    /* couldn't copy directory's Finder comment */
  43.     copyDirAccessPrivsOp    = 3,    /* couldn't copy directory's AFP access privileges */
  44.     copyDirFMAttributesOp    = 4,    /* couldn't copy directory's File Manager attributes */
  45.     dirCreateOp                = 5,    /* couldn't create destination directory */
  46.     fileCopyOp                = 6        /* couldn't copy file */
  47. };
  48.  
  49. /*****************************************************************************/
  50.  
  51. typedef    pascal    Boolean    (*CopyErrProcPtr) (OSErr error,
  52.                                            short failedOperation,
  53.                                            short srcVRefNum,
  54.                                            long srcDirID,
  55.                                            ConstStr255Param srcName,
  56.                                            short dstVRefNum,
  57.                                            long dstDirID,
  58.                                            ConstStr255Param dstName);
  59. /*    ¶ Prototype for the CopyErrProc function DirectoryCopy calls.
  60.     This is the prototype for the CopyErrProc function DirectoryCopy
  61.     calls if an error condition is detected sometime during the copy.  If
  62.     CopyErrProc returns false, then DirectoryCopy attempts to continue with
  63.     the directory copy operation.  If CopyErrProc returns true, then
  64.     DirectoryCopy stops the directory copy operation.
  65.  
  66.     error            input:    The error result code that caused CopyErrProc to
  67.                             be called.
  68.     failedOperation    input:    The operation that returned an error to
  69.                             DirectoryCopy.
  70.     srcVRefNum        input:    Source volume specification.
  71.     srcDirID        input:    Source directory ID.
  72.     srcName            input:    Source file or directory name, or nil if
  73.                             srcDirID specifies the directory.
  74.     dstVRefNum        input:    Destination volume specification.
  75.     dstDirID        input:    Destination directory ID.
  76.     dstName            input:    Destination file or directory name, or nil if
  77.                             dstDirID specifies the directory.
  78.  
  79.     __________
  80.     
  81.     Also see:    FilteredDirectoryCopy, FSpFilteredDirectoryCopy, DirectoryCopy, FSpDirectoryCopy
  82. */
  83.  
  84. #define CallCopyErrProc(userRoutine, error, failedOperation, srcVRefNum, srcDirID, srcName, dstVRefNum, dstDirID, dstName) \
  85.         (*(userRoutine))((error), (failedOperation), (srcVRefNum), (srcDirID), (srcName), (dstVRefNum), (dstDirID), (dstName))
  86.  
  87. /*****************************************************************************/
  88.  
  89. typedef    pascal    Boolean    (*CopyFilterProcPtr) (const CInfoPBRec * const cpbPtr);
  90.  
  91. /*    ¶ Prototype for the CopyFilterProc function.
  92.     This is the prototype for the CopyFilterProc function called by
  93.     FilteredDirectoryCopy and GetLevelSize. If true is returned,
  94.     the file/folder is included in the copy, otherwise it is excluded.
  95.     
  96.     pb    input:    Points to the CInfoPBRec for the item under consideration.
  97.  
  98.     __________
  99.     
  100.     Also see:    FilteredDirectoryCopy, FSpFilteredDirectoryCopy
  101. */
  102.  
  103. #define CallCopyFilterProc(userRoutine, cpbPtr) (*(userRoutine))((cpbPtr))
  104.  
  105. /*****************************************************************************/
  106.  
  107. pascal    OSErr    FilteredDirectoryCopy(short srcVRefNum,
  108.                                       long srcDirID,
  109.                                       ConstStr255Param srcName,
  110.                                       short dstVRefNum,
  111.                                       long dstDirID,
  112.                                       ConstStr255Param dstName,
  113.                                       void *copyBufferPtr,
  114.                                       long copyBufferSize,
  115.                                       Boolean preflight,
  116.                                       CopyErrProcPtr copyErrHandler,
  117.                                       CopyFilterProcPtr copyFilterProc);
  118. /*    ¶ Make a copy of a directory structure in a new location with item filtering.
  119.     The FilteredDirectoryCopy function makes a copy of a directory
  120.     structure in a new location. If copyBufferPtr <> NIL, it points to
  121.     a buffer of copyBufferSize that is used to copy files data. The
  122.     larger the supplied buffer, the faster the copy. If
  123.     copyBufferPtr = NIL, then this routine allocates a buffer in the
  124.     application heap. If you pass a copy buffer to this routine, make
  125.     its size a multiple of 512 ($200) bytes for optimum performance.
  126.     
  127.     The optional copyFilterProc parameter lets a routine you define
  128.     decide what files or directories are copied to the destination.
  129.     
  130.     FilteredDirectoryCopy normally creates a new directory *in* the
  131.     specified destination directory and copies the source directory's
  132.     content into the new directory. However, if root parent directory
  133.     (fsRtParID) is passed as the dstDirID parameter and NULL is
  134.     passed as the dstName parameter, DirectoryCopy renames the
  135.     destination volume to the source directory's name (truncating
  136.     if the name is longer than 27 characters) and copies the source
  137.     directory's content into the destination volume's root directory.
  138.     This special case is supported by FilteredDirectoryCopy, but
  139.     not by FSpFilteredDirectoryCopy since with FSpFilteredDirectoryCopy,
  140.     the dstName parameter can not be NULL.
  141.     
  142.     srcVRefNum        input:    Source volume specification.
  143.     srcDirID        input:    Source directory ID.
  144.     srcName            input:    Source directory name, or nil if
  145.                             srcDirID specifies the directory.
  146.     dstVRefNum        input:    Destination volume specification.
  147.     dstDirID        input:    Destination directory ID.
  148.     dstName            input:    Destination directory name, or nil if
  149.                             dstDirID specifies the directory.
  150.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  151.                             is used the i/o buffer for the copy or
  152.                             nil if you want DirectoryCopy to allocate its
  153.                             own buffer in the application heap.
  154.     copyBufferSize    input:    The size of the buffer pointed to
  155.                             by copyBufferPtr.
  156.     preflight        input:    If true, DirectoryCopy makes sure there are
  157.                             enough allocation blocks on the destination
  158.                             volume to hold the directory's files before
  159.                             starting the copy.
  160.     copyErrHandler    input:    A pointer to the routine you want called if an
  161.                             error condition is detected during the copy, or
  162.                             nil if you don't want to handle error conditions.
  163.                             If you don't handle error conditions, the first
  164.                             error will cause the copy to quit and
  165.                             DirectoryCopy will return the error.
  166.                             Error handling is recommended...
  167.     copyFilterProc    input:    A pointer to the filter routine you want called
  168.                             for each item in the source directory, or NULL
  169.                             if you don't want to filter.
  170.     
  171.     Result Codes
  172.         noErr                0        No error
  173.         readErr                –19        Driver does not respond to read requests
  174.         writErr                –20        Driver does not respond to write requests
  175.         badUnitErr            –21        Driver reference number does not
  176.                                     match unit table
  177.         unitEmptyErr        –22        Driver reference number specifies a
  178.                                     nil handle in unit table
  179.         abortErr            –27        Request aborted by KillIO
  180.         notOpenErr            –28        Driver not open
  181.         dskFulErr            -34        Destination volume is full
  182.         nsvErr                -35        No such volume
  183.         ioErr                -36        I/O error
  184.         bdNamErr            -37        Bad filename
  185.         tmfoErr                -42        Too many files open
  186.         fnfErr                -43        Source file not found, or destination
  187.                                     directory does not exist
  188.         wPrErr                -44        Volume locked by hardware
  189.         fLckdErr            -45        File is locked
  190.         vLckdErr             -46        Destination volume is read-only
  191.         fBsyErr                 -47        The source or destination file could
  192.                                     not be opened with the correct access
  193.                                     modes
  194.         dupFNErr            -48        Destination file already exists
  195.         opWrErr                -49        File already open for writing
  196.         paramErr            -50        No default volume or function not
  197.                                     supported by volume
  198.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  199.         memFullErr            -108    Copy buffer could not be allocated
  200.         dirNFErr            -120    Directory not found or incomplete pathname
  201.         wrgVolTypErr        -123    Function not supported by volume
  202.         afpAccessDenied        -5000    User does not have the correct access
  203.         afpDenyConflict        -5006    The source or destination file could
  204.                                     not be opened with the correct access
  205.                                     modes
  206.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  207.                                     or incomplete pathname
  208.     
  209.     __________
  210.     
  211.     Also see:    CopyErrProcPtr, CopyFilterProcPtr, FSpFilteredDirectoryCopy,
  212.                 DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
  213. */
  214.  
  215. /*****************************************************************************/
  216.  
  217. pascal    OSErr    FSpFilteredDirectoryCopy(const FSSpec *srcSpec,
  218.                                          const FSSpec *dstSpec,
  219.                                          void *copyBufferPtr,
  220.                                          long copyBufferSize,
  221.                                          Boolean preflight,
  222.                                          CopyErrProcPtr copyErrHandler,
  223.                                          CopyFilterProcPtr copyFilterProc);
  224. /*    ¶ Make a copy of a directory structure in a new location with item filtering.
  225.     The FSpFilteredDirectoryCopy function makes a copy of a directory
  226.     structure in a new location. If copyBufferPtr <> NIL, it points to
  227.     a buffer of copyBufferSize that is used to copy files data. The
  228.     larger the supplied buffer, the faster the copy. If
  229.     copyBufferPtr = NIL, then this routine allocates a buffer in the
  230.     application heap. If you pass a copy buffer to this routine, make
  231.     its size a multiple of 512 ($200) bytes for optimum performance.
  232.     
  233.     The optional copyFilterProc parameter lets a routine you define
  234.     decide what files or directories are copied to the destination.
  235.     
  236.     srcSpec            input:    An FSSpec record specifying the directory to copy.
  237.     dstSpec            input:    An FSSpec record specifying destination directory
  238.                             of the copy.
  239.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  240.                             is used the i/o buffer for the copy or
  241.                             nil if you want DirectoryCopy to allocate its
  242.                             own buffer in the application heap.
  243.     copyBufferSize    input:    The size of the buffer pointed to
  244.                             by copyBufferPtr.
  245.     preflight        input:    If true, FSpDirectoryCopy makes sure there are
  246.                             enough allocation blocks on the destination
  247.                             volume to hold the directory's files before
  248.                             starting the copy.
  249.     copyErrHandler    input:    A pointer to the routine you want called if an
  250.                             error condition is detected during the copy, or
  251.                             nil if you don't want to handle error conditions.
  252.                             If you don't handle error conditions, the first
  253.                             error will cause the copy to quit and
  254.                             DirectoryCopy will return the error.
  255.                             Error handling is recommended...
  256.     copyFilterProc    input:    A pointer to the filter routine you want called
  257.                             for each item in the source directory, or NULL
  258.                             if you don't want to filter.
  259.     
  260.     Result Codes
  261.         noErr                0        No error
  262.         readErr                –19        Driver does not respond to read requests
  263.         writErr                –20        Driver does not respond to write requests
  264.         badUnitErr            –21        Driver reference number does not
  265.                                     match unit table
  266.         unitEmptyErr        –22        Driver reference number specifies a
  267.                                     nil handle in unit table
  268.         abortErr            –27        Request aborted by KillIO
  269.         notOpenErr            –28        Driver not open
  270.         dskFulErr            -34        Destination volume is full
  271.         nsvErr                -35        No such volume
  272.         ioErr                -36        I/O error
  273.         bdNamErr            -37        Bad filename
  274.         tmfoErr                -42        Too many files open
  275.         fnfErr                -43        Source file not found, or destination
  276.                                     directory does not exist
  277.         wPrErr                -44        Volume locked by hardware
  278.         fLckdErr            -45        File is locked
  279.         vLckdErr             -46        Destination volume is read-only
  280.         fBsyErr                 -47        The source or destination file could
  281.                                     not be opened with the correct access
  282.                                     modes
  283.         dupFNErr            -48        Destination file already exists
  284.         opWrErr                -49        File already open for writing
  285.         paramErr            -50        No default volume or function not
  286.                                     supported by volume
  287.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  288.         memFullErr            -108    Copy buffer could not be allocated
  289.         dirNFErr            -120    Directory not found or incomplete pathname
  290.         wrgVolTypErr        -123    Function not supported by volume
  291.         afpAccessDenied        -5000    User does not have the correct access
  292.         afpDenyConflict        -5006    The source or destination file could
  293.                                     not be opened with the correct access
  294.                                     modes
  295.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  296.                                     or incomplete pathname
  297.     
  298.     __________
  299.     
  300.     Also see:    CopyErrProcPtr, CopyFilterProcPtr, FilteredDirectoryCopy,
  301.                 DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
  302. */
  303.  
  304. /*****************************************************************************/
  305.  
  306. pascal    OSErr    DirectoryCopy(short srcVRefNum,
  307.                               long srcDirID,
  308.                               ConstStr255Param srcName,
  309.                               short dstVRefNum,
  310.                               long dstDirID,
  311.                               ConstStr255Param dstName,
  312.                               void *copyBufferPtr,
  313.                               long copyBufferSize,
  314.                               Boolean preflight,
  315.                               CopyErrProcPtr copyErrHandler);
  316. /*    ¶ Make a copy of a directory structure in a new location.
  317.     The DirectoryCopy function makes a copy of a directory structure in a
  318.     new location. If copyBufferPtr <> NIL, it points to a buffer of
  319.     copyBufferSize that is used to copy files data.  The larger the
  320.     supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then this
  321.     routine allocates a buffer in the application heap. If you pass a
  322.     copy buffer to this routine, make its size a multiple of 512
  323.     ($200) bytes for optimum performance.
  324.     
  325.     DirectoryCopy normally creates a new directory *in* the specified
  326.     destination directory and copies the source directory's content into
  327.     the new directory. However, if root parent directory (fsRtParID)
  328.     is passed as the dstDirID parameter and NULL is passed as the
  329.     dstName parameter, DirectoryCopy renames the destination volume to
  330.     the source directory's name (truncating if the name is longer than
  331.     27 characters) and copies the source directory's content into the
  332.     destination volume's root directory. This special case is supported
  333.     by DirectoryCopy, but not by FSpDirectoryCopy since with
  334.     FSpDirectoryCopy, the dstName parameter can not be NULL.
  335.     
  336.     srcVRefNum        input:    Source volume specification.
  337.     srcDirID        input:    Source directory ID.
  338.     srcName            input:    Source directory name, or nil if
  339.                             srcDirID specifies the directory.
  340.     dstVRefNum        input:    Destination volume specification.
  341.     dstDirID        input:    Destination directory ID.
  342.     dstName            input:    Destination directory name, or nil if
  343.                             dstDirID specifies the directory.
  344.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  345.                             is used the i/o buffer for the copy or
  346.                             nil if you want DirectoryCopy to allocate its
  347.                             own buffer in the application heap.
  348.     copyBufferSize    input:    The size of the buffer pointed to
  349.                             by copyBufferPtr.
  350.     preflight        input:    If true, DirectoryCopy makes sure there are
  351.                             enough allocation blocks on the destination
  352.                             volume to hold the directory's files before
  353.                             starting the copy.
  354.     copyErrHandler    input:    A pointer to the routine you want called if an
  355.                             error condition is detected during the copy, or
  356.                             nil if you don't want to handle error conditions.
  357.                             If you don't handle error conditions, the first
  358.                             error will cause the copy to quit and
  359.                             DirectoryCopy will return the error.
  360.                             Error handling is recommended...
  361.     
  362.     Result Codes
  363.         noErr                0        No error
  364.         readErr                –19        Driver does not respond to read requests
  365.         writErr                –20        Driver does not respond to write requests
  366.         badUnitErr            –21        Driver reference number does not
  367.                                     match unit table
  368.         unitEmptyErr        –22        Driver reference number specifies a
  369.                                     nil handle in unit table
  370.         abortErr            –27        Request aborted by KillIO
  371.         notOpenErr            –28        Driver not open
  372.         dskFulErr            -34        Destination volume is full
  373.         nsvErr                -35        No such volume
  374.         ioErr                -36        I/O error
  375.         bdNamErr            -37        Bad filename
  376.         tmfoErr                -42        Too many files open
  377.         fnfErr                -43        Source file not found, or destination
  378.                                     directory does not exist
  379.         wPrErr                -44        Volume locked by hardware
  380.         fLckdErr            -45        File is locked
  381.         vLckdErr             -46        Destination volume is read-only
  382.         fBsyErr                 -47        The source or destination file could
  383.                                     not be opened with the correct access
  384.                                     modes
  385.         dupFNErr            -48        Destination file already exists
  386.         opWrErr                -49        File already open for writing
  387.         paramErr            -50        No default volume or function not
  388.                                     supported by volume
  389.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  390.         memFullErr            -108    Copy buffer could not be allocated
  391.         dirNFErr            -120    Directory not found or incomplete pathname
  392.         wrgVolTypErr        -123    Function not supported by volume
  393.         afpAccessDenied        -5000    User does not have the correct access
  394.         afpDenyConflict        -5006    The source or destination file could
  395.                                     not be opened with the correct access
  396.                                     modes
  397.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  398.                                     or incomplete pathname
  399.     
  400.     __________
  401.     
  402.     Also see:    CopyErrProcPtr, FSpDirectoryCopy, FilteredDirectoryCopy,
  403.                 FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
  404. */
  405.  
  406. /*****************************************************************************/
  407.  
  408. pascal    OSErr    FSpDirectoryCopy(const FSSpec *srcSpec,
  409.                                  const FSSpec *dstSpec,
  410.                                  void *copyBufferPtr,
  411.                                  long copyBufferSize,
  412.                                  Boolean preflight,
  413.                                  CopyErrProcPtr copyErrHandler);
  414. /*    ¶ Make a copy of a directory structure in a new location.
  415.     The FSpDirectoryCopy function makes a copy of a directory structure in a
  416.     new location. If copyBufferPtr <> NIL, it points to a buffer of
  417.     copyBufferSize that is used to copy files data.  The larger the
  418.     supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then this
  419.     routine allocates a buffer in the application heap. If you pass a
  420.     copy buffer to this routine, make its size a multiple of 512
  421.     ($200) bytes for optimum performance.
  422.     
  423.     srcSpec            input:    An FSSpec record specifying the directory to copy.
  424.     dstSpec            input:    An FSSpec record specifying destination directory
  425.                             of the copy.
  426.     copyBufferPtr    input:    Points to a buffer of copyBufferSize that
  427.                             is used the i/o buffer for the copy or
  428.                             nil if you want DirectoryCopy to allocate its
  429.                             own buffer in the application heap.
  430.     copyBufferSize    input:    The size of the buffer pointed to
  431.                             by copyBufferPtr.
  432.     preflight        input:    If true, FSpDirectoryCopy makes sure there are
  433.                             enough allocation blocks on the destination
  434.                             volume to hold the directory's files before
  435.                             starting the copy.
  436.     copyErrHandler    input:    A pointer to the routine you want called if an
  437.                             error condition is detected during the copy, or
  438.                             nil if you don't want to handle error conditions.
  439.                             If you don't handle error conditions, the first
  440.                             error will cause the copy to quit and
  441.                             DirectoryCopy will return the error.
  442.                             Error handling is recommended...
  443.     
  444.     Result Codes
  445.         noErr                0        No error
  446.         readErr                –19        Driver does not respond to read requests
  447.         writErr                –20        Driver does not respond to write requests
  448.         badUnitErr            –21        Driver reference number does not
  449.                                     match unit table
  450.         unitEmptyErr        –22        Driver reference number specifies a
  451.                                     nil handle in unit table
  452.         abortErr            –27        Request aborted by KillIO
  453.         notOpenErr            –28        Driver not open
  454.         dskFulErr            -34        Destination volume is full
  455.         nsvErr                -35        No such volume
  456.         ioErr                -36        I/O error
  457.         bdNamErr            -37        Bad filename
  458.         tmfoErr                -42        Too many files open
  459.         fnfErr                -43        Source file not found, or destination
  460.                                     directory does not exist
  461.         wPrErr                -44        Volume locked by hardware
  462.         fLckdErr            -45        File is locked
  463.         vLckdErr             -46        Destination volume is read-only
  464.         fBsyErr                 -47        The source or destination file could
  465.                                     not be opened with the correct access
  466.                                     modes
  467.         dupFNErr            -48        Destination file already exists
  468.         opWrErr                -49        File already open for writing
  469.         paramErr            -50        No default volume or function not
  470.                                     supported by volume
  471.         permErr                 -54        File is already open and cannot be opened using specified deny modes
  472.         memFullErr            -108    Copy buffer could not be allocated
  473.         dirNFErr            -120    Directory not found or incomplete pathname
  474.         wrgVolTypErr        -123    Function not supported by volume
  475.         afpAccessDenied        -5000    User does not have the correct access
  476.         afpDenyConflict        -5006    The source or destination file could
  477.                                     not be opened with the correct access
  478.                                     modes
  479.         afpObjectTypeErr    -5025    Source is a directory, directory not found
  480.                                     or incomplete pathname
  481.     
  482.     __________
  483.     
  484.     Also see:    CopyErrProcPtr, DirectoryCopy, FilteredDirectoryCopy,
  485.                 FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
  486. */
  487.  
  488. /*****************************************************************************/
  489.  
  490. #ifdef __cplusplus
  491. }
  492. #endif
  493.  
  494. #include "OptimizationEnd.h"
  495.  
  496. #endif    /* __DIRECTORYCOPY__ */
  497.